extends Node3D

var pause = false

@onready var player: GameCharacter = $Player
@onready var inventory_interface: InventoryInterface = $UI/InventoryInterface
@onready var pause_label: Label = $UI/MarginContainer/PauseLabel

func _ready() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	player.toggle_inventory.connect(toggle_inventory_interface)
	inventory_interface.populate_inventory_data(player.inventory)

func _process(delta: float) -> void:
	pass

func _unhandled_input(event: InputEvent) -> void:
	# Handle pause
	if Input.is_action_just_pressed("escape"):
		pause = not pause
	if not pause and not inventory_interface.visible:
		Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	else:
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	if not inventory_interface.visible:
		player.ignore_input = pause
	pause_label.visible = pause

func toggle_inventory_interface() -> void:
	inventory_interface.visible = not inventory_interface.visible
	player.ignore_input = inventory_interface.visible
	if inventory_interface.visible:
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	else:
		Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
